import axios from 'axios'

const instance = axios.create({
  baseURL: '/api'
})

instance.interceptors.request.use(
  config => config,
  error => Promise.reject(error)
)

instance.interceptors.response.use(
  response => {
    const { message, success } = response.data
    if (success) {
      return response
    } else {
      return Promise.reject(new Error(message))
    }
  },
  error => Promise.reject(error)
)

export default instance

